<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: HashWithIndifferentAccess</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">HashWithIndifferentAccess</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Hash
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This class has dubious semantics and we only have it so that people can
write params[:key] instead of params[&#8216;key&#8217;] and they get the
same value for both keys.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000133">[]=</a>&nbsp;&nbsp;
      <a href="#M000145">convert_key</a>&nbsp;&nbsp;
      <a href="#M000146">convert_value</a>&nbsp;&nbsp;
      <a href="#M000132">default</a>&nbsp;&nbsp;
      <a href="#M000140">delete</a>&nbsp;&nbsp;
      <a href="#M000138">dup</a>&nbsp;&nbsp;
      <a href="#M000136">fetch</a>&nbsp;&nbsp;
      <a href="#M000135">key?</a>&nbsp;&nbsp;
      <a href="#M000139">merge</a>&nbsp;&nbsp;
      <a href="#M000131">new</a>&nbsp;&nbsp;
      <a href="#M000141">stringify_keys!</a>&nbsp;&nbsp;
      <a href="#M000142">symbolize_keys!</a>&nbsp;&nbsp;
      <a href="#M000144">to_hash</a>&nbsp;&nbsp;
      <a href="#M000143">to_options!</a>&nbsp;&nbsp;
      <a href="#M000134">update</a>&nbsp;&nbsp;
      <a href="#M000137">values_at</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">



    <div id="aliases-list">
      <h3 class="section-bar">External Aliases</h3>

      <div class="name-list">
                        <table summary="aliases">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">[]=</td>
          <td>-&gt;</td>
          <td class="context-item-value">regular_writer</td>
        </tr>
                        </table>
      </div>
    </div>


      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000131" class="method-detail">
        <a name="M000131"></a>

        <div class="method-heading">
          <a href="#M000131" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(constructor = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000131-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000131-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 6</span>
 6:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">constructor</span> = {})
 7:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">constructor</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
 8:       <span class="ruby-keyword kw">super</span>()
 9:       <span class="ruby-identifier">update</span>(<span class="ruby-identifier">constructor</span>)
10:     <span class="ruby-keyword kw">else</span>
11:       <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">constructor</span>)
12:     <span class="ruby-keyword kw">end</span>
13:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000133" class="method-detail">
        <a name="M000133"></a>

        <div class="method-heading">
          <a href="#M000133" class="method-signature">
          <span class="method-name">[]=</span><span class="method-args">(key, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Assigns a <a href="HashWithIndifferentAccess.html#M000131">new</a> value to
the hash:
</p>
<pre>
  hash = HashWithIndifferentAccess.new
  hash[:key] = &quot;value&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000133-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000133-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 31</span>
31:   <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
32:     <span class="ruby-identifier">regular_writer</span>(<span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>), <span class="ruby-identifier">convert_value</span>(<span class="ruby-identifier">value</span>))
33:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000145" class="method-detail">
        <a name="M000145"></a>

        <div class="method-heading">
          <a href="#M000145" class="method-signature">
          <span class="method-name">convert_key</span><span class="method-args">(key)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000145-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000145-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 109</span>
109:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>)
110:       <span class="ruby-identifier">key</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">key</span>
111:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000146" class="method-detail">
        <a name="M000146"></a>

        <div class="method-heading">
          <a href="#M000146" class="method-signature">
          <span class="method-name">convert_value</span><span class="method-args">(value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000146-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000146-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 113</span>
113:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">convert_value</span>(<span class="ruby-identifier">value</span>)
114:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">value</span>
115:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
116:         <span class="ruby-identifier">value</span>.<span class="ruby-identifier">with_indifferent_access</span>
117:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>
118:         <span class="ruby-identifier">value</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">with_indifferent_access</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">e</span> }
119:       <span class="ruby-keyword kw">else</span>
120:         <span class="ruby-identifier">value</span>
121:       <span class="ruby-keyword kw">end</span>
122:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000132" class="method-detail">
        <a name="M000132"></a>

        <div class="method-heading">
          <a href="#M000132" class="method-signature">
          <span class="method-name">default</span><span class="method-args">(key = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000132-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000132-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 15</span>
15:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span>(<span class="ruby-identifier">key</span> = <span class="ruby-keyword kw">nil</span>)
16:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>)
17:       <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">key</span>]
18:     <span class="ruby-keyword kw">else</span>
19:       <span class="ruby-keyword kw">super</span>
20:     <span class="ruby-keyword kw">end</span>
21:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000140" class="method-detail">
        <a name="M000140"></a>

        <div class="method-heading">
          <a href="#M000140" class="method-signature">
          <span class="method-name">delete</span><span class="method-args">(key)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Removes a specified key from the hash.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000140-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000140-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 95</span>
95:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
96:     <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>))
97:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000138" class="method-detail">
        <a name="M000138"></a>

        <div class="method-heading">
          <a href="#M000138" class="method-signature">
          <span class="method-name">dup</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an exact copy of the hash.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000138-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000138-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 84</span>
84:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>
85:     <span class="ruby-constant">HashWithIndifferentAccess</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>)
86:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000136" class="method-detail">
        <a name="M000136"></a>

        <div class="method-heading">
          <a href="#M000136" class="method-signature">
          <span class="method-name">fetch</span><span class="method-args">(key, *extras)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Fetches the value for the specified key, same as doing hash[key]
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000136-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000136-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 68</span>
68:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">extras</span>)
69:     <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>), <span class="ruby-operator">*</span><span class="ruby-identifier">extras</span>)
70:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000135" class="method-detail">
        <a name="M000135"></a>

        <div class="method-heading">
          <a href="#M000135" class="method-signature">
          <span class="method-name">key?</span><span class="method-args">(key)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks the hash for a key matching the argument passed in:
</p>
<pre>
  hash = HashWithIndifferentAccess.new
  hash[&quot;key&quot;] = &quot;value&quot;
  hash.key? :key  # =&gt; true
  hash.key? &quot;key&quot; # =&gt; true
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000135-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000135-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 59</span>
59:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">key?</span>(<span class="ruby-identifier">key</span>)
60:     <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>))
61:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000139" class="method-detail">
        <a name="M000139"></a>

        <div class="method-heading">
          <a href="#M000139" class="method-signature">
          <span class="method-name">merge</span><span class="method-args">(hash)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Merges the instantized and the specified hashes together, giving precedence
to the values from the second hash Does not overwrite the existing hash.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000139-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000139-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 90</span>
90:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">merge</span>(<span class="ruby-identifier">hash</span>)
91:     <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">hash</span>)
92:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000141" class="method-detail">
        <a name="M000141"></a>

        <div class="method-heading">
          <a href="#M000141" class="method-signature">
          <span class="method-name">stringify_keys!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000141-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000141-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 99</span>
99:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stringify_keys!</span>; <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000142" class="method-detail">
        <a name="M000142"></a>

        <div class="method-heading">
          <a href="#M000142" class="method-signature">
          <span class="method-name">symbolize_keys!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000142-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000142-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 100</span>
100:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">symbolize_keys!</span>; <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000144" class="method-detail">
        <a name="M000144"></a>

        <div class="method-heading">
          <a href="#M000144" class="method-signature">
          <span class="method-name">to_hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert to a Hash with String keys.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000144-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000144-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 104</span>
104:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_hash</span>
105:     <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">default</span>).<span class="ruby-identifier">merge</span>(<span class="ruby-keyword kw">self</span>)
106:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000143" class="method-detail">
        <a name="M000143"></a>

        <div class="method-heading">
          <a href="#M000143" class="method-signature">
          <span class="method-name">to_options!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000143-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000143-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 101</span>
101:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_options!</span>; <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000134" class="method-detail">
        <a name="M000134"></a>

        <div class="method-heading">
          <a href="#M000134" class="method-signature">
          <span class="method-name">update</span><span class="method-args">(other_hash)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Updates the instantized hash with values from the second:
</p>
<pre>
  hash_1 = HashWithIndifferentAccess.new
  hash_1[:key] = &quot;value&quot;

  hash_2 = HashWithIndifferentAccess.new
  hash_2[:key] = &quot;New Value!&quot;

  hash_1.update(hash_2) # =&gt; {&quot;key&quot;=&gt;&quot;New Value!&quot;}
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000134-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000134-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 45</span>
45:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>(<span class="ruby-identifier">other_hash</span>)
46:     <span class="ruby-identifier">other_hash</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">regular_writer</span>(<span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>), <span class="ruby-identifier">convert_value</span>(<span class="ruby-identifier">value</span>)) }
47:     <span class="ruby-keyword kw">self</span>
48:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000137" class="method-detail">
        <a name="M000137"></a>

        <div class="method-heading">
          <a href="#M000137" class="method-signature">
          <span class="method-name">values_at</span><span class="method-args">(*indices)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of the values at the specified indices:
</p>
<pre>
  hash = HashWithIndifferentAccess.new
  hash[:a] = &quot;x&quot;
  hash[:b] = &quot;y&quot;
  hash.values_at(&quot;a&quot;, &quot;b&quot;) # =&gt; [&quot;x&quot;, &quot;y&quot;]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000137-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000137-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 79</span>
79:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">values_at</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">indices</span>)
80:     <span class="ruby-identifier">indices</span>.<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">convert_key</span>(<span class="ruby-identifier">key</span>)]}
81:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>